/**
* @file gui_main.c
* @brief gui entry and define
* @details 
* @author huangbin
* @version V1.0.0
* @date 2025-06-12
* @copyright All documents are copyrighted by Shenzhen Xinlongwei Technology Co., LTD.
*            They may not be used for commercial purposes without permission
*/

/*============================ INCLUDES ======================================*/

#define __GUI_MESSAGE_INHERIT__
#define __GUI_CORE_IMPLEMENT__
#include "inc.h"

#if defined(__clang__)
//#   pragma clang diagnostic push
#   pragma clang diagnostic ignored "-Wunknown-warning-option"
#   pragma clang diagnostic ignored "-Wreserved-identifier"
#   pragma clang diagnostic ignored "-Wsign-conversion"
#   pragma clang diagnostic ignored "-Wpadded"
#   pragma clang diagnostic ignored "-Wcast-qual"
#   pragma clang diagnostic ignored "-Wcast-align"
#   pragma clang diagnostic ignored "-Wmissing-field-initializers"
#   pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
#   pragma clang diagnostic ignored "-Wmissing-prototypes"
#   pragma clang diagnostic ignored "-Wunused-variable"
#   pragma clang diagnostic ignored "-Wunused-parameter"
#   pragma clang diagnostic ignored "-Wgnu-statement-expression"
#   pragma clang diagnostic ignored "-Wtautological-pointer-compare"
#elif __IS_COMPILER_ARM_COMPILER_5__
#elif __IS_COMPILER_GCC__
#   pragma GCC diagnostic push
#   pragma GCC diagnostic ignored "-Wformat="
#   pragma GCC diagnostic ignored "-Wpedantic"
#endif

/*============================ MACROS ========================================*/
#undef this
#define this    (*ptThis)
/*============================ MACROFIED FUNCTIONS ===========================*/
/*============================ TYPES =========================================*/
/*============================ GLOBAL VARIABLES ==============================*/
/*============================ PROTOTYPES ====================================*/
#include "gui_message.h"

xm_gui_t g_tGUI;

bool UserMessagePreprocessingHandler(  xm_gui_t *ptThis, gui_msg_core_t *ptMSG)
{
	uint_fast8_t uMsgId = gui_helper_msg_item_get_id(ptMSG);
	
	
	if((uMsgId == GUI_MSG_KEY_EVT_DOWN)
		|| (uMsgId == GUI_MSG_KEY_EVT_LONG_PRESSING)
		|| (uMsgId == GUI_MSG_KEY_EVT_REPEAT))
	{
//		if(gSet.chBeepSet == ON)
//			Beep(5,5,1);
//		if(ClearSleepTimeByKey()) //如果是唤醒，不再发送消息
//			return true;
	}
//	if(GetSystemRunStatus() == false) //如果系统sleep，所有消息都不再发送
//		return true;

	return false;
}
xm_gui_t *guiGetInstance(void)
{
	return &g_tGUI;
}
void xmGuiInit(void)
{
   static gui_msg_t s_tMSGArray[32];
   static gui_msg_pointer_frontend_pipeline_t s_tPointerPipelines[2];

	static const xm_gui_cfg_t c_tCFG = {
        .fnDispAdapterTask = &__disp_adapter0_task,
        .ptDispAdapter = &DISP0_ADAPTER,

        .Message = {
            .ptItems = s_tMSGArray,
            .hwCount = dimof(s_tMSGArray),
        },

        .tKeyFrontend = {
            .u4First3RepeatInterval = 5,
            .u4RestRepeatInterval = 3,
            .u10DoubleClickLimit = 200,
        },

        .tPointerFrontend = {
            .u10DoubleClickLimit = 500,
        },

        .ptPipelines = s_tPointerPipelines,
        .chPipelineNo = dimof(s_tPointerPipelines),
        .fnUserMessagePreprocessingHandler = UserMessagePreprocessingHandler,
    };
    gui_init(&g_tGUI, (xm_gui_cfg_t *)&c_tCFG);	
}
bool ptInRect(int16_t x,int16_t y,arm_2d_region_t *region)
{
    if((x > region->tLocation.iX) && (x < region->tLocation.iX + region->tSize.iWidth))
        if((y > region->tLocation.iY) && (y < region->tLocation.iY + region->tSize.iHeight))
            return true;
    return false;
}

void __disp_adapter0_vres_read_memory( intptr_t pObj, 
                                                void *pBuffer,
                                                uintptr_t pAddress,
                                                size_t nSizeInByte)
{
}
uintptr_t __disp_adapter0_vres_get_asset_address(
                                                        uintptr_t pObj,
                                                        arm_2d_vres_t *ptVRES)
{
    return 0;
}
//#if USE_AUTO_LOADER_DEMO == 1
//user_scene_mainmenu_t *__arm_2d_scene_mainmenu_init(   arm_2d_scene_player_t *ptDispAdapter, 
//                                        user_scene_mainmenu_t *ptScene)
//{
//    return NULL;
//}
//#endif

